package com.cat.bitOperation;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-flips-to-make-a-or-b-equal-to-c/description/
 * @create 2025/8/22 11:25
 * @since JDK17
 */

public class Solution11 {
    public int minFlips(int a, int b, int c) {
        int t = a | b, ans = 0;
        for (int i = 0; i < 31; i++) {
            if ((t >> i & 1) != (c >> i & 1)) { //
                if ((c >> i & 1) != 0) {
                    ans++;
                } else {
                    ans += (a >> i & 1) != 0 ? 1 : 0;
                    ans += (b >> i & 1) != 0 ? 1 : 0;
                }
            }
        }
        return ans;
    }
}
